//
//  MyCollectCellTableViewCell.m
//  diaoyuren
//
//  Created by 钓鱼人 on 16/3/23.
//  Copyright © 2016年 game. All rights reserved.
//

#import "MyCollectCellTableViewCell.h"
#import "PageImgModel.h"
#import "UIImageView+WebCache.h"
#define imageXD 8 //图片间的间隙
#define imageWidth ((SCREEN_WIDTH-imageXD*4)/3)
#define cellhightCount ((SCREEN_HEIGHT*0.065*2)+SCREEN_HEIGHT*0.02)


@interface MyCollectCellTableViewCell ()
/**
 *  显示收藏时间文字lab
 */
@property (weak, nonatomic) IBOutlet UILabel *colletimeLab;
/**
 *  具体的收藏时间
 */
@property (weak, nonatomic) IBOutlet UILabel *time;
/**
 *  承载 收藏时间 取消收藏的View 宽高
 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *timeViewHight;

/**
 *  承载标题的View 高
 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleViewHight;

/**
 *  标题
 */
@property (weak, nonatomic) IBOutlet UILabel *title;
/**
 *  取消收藏btn
 */
@property (weak, nonatomic) IBOutlet UIButton *cancelBtn;
/**
 *  底部灰色的View 高
 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *footViewHight;
/**
 *  箭头img
 */
@property (weak, nonatomic) IBOutlet UIImageView *gotoImg;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *goyoImgWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *gotoImgHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lin1Hight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lin2Hight;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *linHight1;

@property (weak, nonatomic) IBOutlet UIView *imageCount3;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *image3Width;
@property (weak, nonatomic) IBOutlet UIImageView *count3Image1;
@property (weak, nonatomic) IBOutlet UIImageView *count3Image2;
@property (weak, nonatomic) IBOutlet UIImageView *count3Image3;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageback3Hight;

@property (weak, nonatomic) IBOutlet UIView *imageCount2;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *image2Width;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *videoImgOffect;
@property (weak, nonatomic) IBOutlet UIImageView *count2Image1;
@property (weak, nonatomic) IBOutlet UIImageView *count2Image2;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageback2Hight;

@property (weak, nonatomic) IBOutlet UIView *imageCount1;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *image1Width;
@property (weak, nonatomic) IBOutlet UIImageView *count1Image;
@property (weak, nonatomic) IBOutlet UIImageView *videoImg;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageback1Hight;

@property (weak, nonatomic) IBOutlet UIView *textViewBack;
@property (weak, nonatomic) IBOutlet UITextView *textview;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *textViewBackHight;
@property (weak, nonatomic) IBOutlet UILabel *cellFoot;


@end

@implementation MyCollectCellTableViewCell

- (void)awakeFromNib {

//    self.cellFoot.backgroundColor = tabGropBackColor;
    self.contentView.backgroundColor = tabGropBackColor;
    self.textview.backgroundColor = [UIColor whiteColor];
    self.textview.font = font(SCREEN_WIDTH*0.045);
//    self.textview.selectable = NO;
//    self.textview.userInteractionEnabled = YES;
    
    _textview.scrollEnabled = NO;
    _textview.userInteractionEnabled = NO;
    _textview.editable = NO;
    
    self.lin1Hight.constant = 0.5;
    self.lin2Hight.constant = 0.5;
    
    self.linHight1.constant = 0.5;
    
    
    self.image3Width.constant = imageWidth;
    self.image2Width.constant = imageWidth;
    self.image1Width.constant = imageWidth;
    self.videoImgOffect.constant =  -imageWidth-8;
    
    
    self.timeViewHight.constant = SCREEN_HEIGHT*0.075;
    self.titleViewHight.constant = SCREEN_HEIGHT*0.065;
    
    self.footViewHight.constant = SCREEN_HEIGHT*0.02;
    
    self.goyoImgWidth.constant = SCREEN_WIDTH*0.025;
    self.gotoImgHeight.constant = SCREEN_HEIGHT*0.02;
    self.selectionStyle = 0;
    
    // 时间
    self.colletimeLab.font = font(SCREEN_WIDTH*0.036);
    self.time.font = font(SCREEN_WIDTH*0.036);
    
    //标题
    self.title.font = Boldfont(SCREEN_WIDTH*0.05);
    
    //取消收藏操作
    self.cancelBtn.titleLabel.font = font(SCREEN_WIDTH*0.036);
    
    self.cancelBtn.layer.borderColor = linColor.CGColor;
    self.cancelBtn.layer.borderWidth = 0.4;
    radius(self.cancelBtn, 2);
    
    [self UIAlphaSet];
}

-(void)UIAlphaSet{

    self.videoImg.alpha = 0;
    
    self.imageback1Hight.constant = 0;
    self.imageback2Hight.constant = 0;
    self.imageback3Hight.constant = 0;
    self.textViewBackHight.constant = 0;
}

- (IBAction)cancelClick:(id)sender {
    
    [self.deleget CellCancelClick:self];
}
-(void)layoutSubviews{

}
-(void)setCollectSelectmodel:(CollectThreadModel *)collectSelectmodel{
    _collectSelectmodel = collectSelectmodel;
    
    if (_collectSelectmodel) {
        
        [self UIAlphaSet];

        if ([_collectSelectmodel.style isEqualToString:@"text"]) {
           
            self.textview.text = _collectSelectmodel.message;
            CGSize textSize = [self.textview sizeThatFits:CGSizeMake(SCREEN_WIDTH-25, 1000.0f)];
            self.textViewBackHight.constant =textSize.height;
            self.cellHight = textSize.height+cellhightCount+30;
         
        }else if([_collectSelectmodel.style isEqualToString:@"video"]){
          
            PageImgModel *imageModel= _collectSelectmodel.images_list[0];
            [self.count1Image sd_setImageWithURL:[NSURL URLWithString:imageModel.image_url]];
       
            self.imageback1Hight.constant = imageWidth;
            self.videoImg.alpha = 1;
            self.cellHight = imageWidth+cellhightCount;
            
        }else{
            NSInteger count = _collectSelectmodel.images_list.count;
            
            if (count>3) {
                count=3;
            }
            
            if (count==1) {
       
                 self.imageback1Hight.constant = imageWidth;
                PageImgModel *imageModel= _collectSelectmodel.images_list[0];
                [self.count1Image sd_setImageWithURL:[NSURL URLWithString:imageModel.image_url]];
            
                
            }else if (count==2){
            
                 self.imageback2Hight.constant = imageWidth;
           
                PageImgModel *imageModel= _collectSelectmodel.images_list[0];
                [self.count2Image1 sd_setImageWithURL:[NSURL URLWithString:imageModel.image_url]];
                
                PageImgModel *imageModel2= _collectSelectmodel.images_list[1];
                [self.count2Image2 sd_setImageWithURL:[NSURL URLWithString:imageModel2.image_url]];
                
            }else if (count==3){
                [self UIAlphaSet];
                 self.imageback3Hight.constant = imageWidth;
                PageImgModel *imageModel= _collectSelectmodel.images_list[0];
                [self.count3Image1 sd_setImageWithURL:[NSURL URLWithString:imageModel.image_url]];
                
                PageImgModel *imageModel2= _collectSelectmodel.images_list[1];
                [self.count3Image2 sd_setImageWithURL:[NSURL URLWithString:imageModel2.image_url]];
                PageImgModel *imageModel3= _collectSelectmodel.images_list[2];
                [self.count3Image3 sd_setImageWithURL:[NSURL URLWithString:imageModel3.image_url]];
                
                
              
            }
        
            
            self.cellHight = imageWidth+cellhightCount+30;
        }
    
        
        self.height = self.cellHight;
        self.time.text = _collectSelectmodel.formate_date;
        self.title.text = _collectSelectmodel.title;
        
        self.tid = _collectSelectmodel.tid;
    }

}


-(void)setArticleModel:(ArticleCollectModel *)articleModel{

    _articleModel = articleModel;
    
    if (_articleModel) {
        
        [self UIAlphaSet];
        
        self.textview.text = _articleModel.cription;
        CGSize textSize = [self.textview sizeThatFits:CGSizeMake(SCREEN_WIDTH-25, 1000.0f)];
        self.textViewBackHight.constant =textSize.height;
        self.cellHight = textSize.height+cellhightCount+30;
        
        self.height = self.cellHight;
        self.time.text = _articleModel.addtime;
        self.title.text = _articleModel.title;
        self.tid = _articleModel.aid;
        
        self.skin = _articleModel.skin.integerValue;
    }

}
@end
